﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using ProjTemp.Common.Logging;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Events;
using ProjTemp.Desktop.Common.ViewModel;
using Microsoft.Practices.ServiceLocation;
using ProjTemp.Common;
using System.Windows.Threading;

namespace Mysoft.ServerMonitoring.OMKit.AlertHandling.ViewModels
{
    [Export(typeof(AlertHandlingViewModel))]
    [PartCreationPolicy(CreationPolicy.Shared)]
    internal class AlertHandlingViewModel : VMBase<string>
    {
        [ImportingConstructor]
        public AlertHandlingViewModel(ILogger logger, IRegionManager regionManager, IEventAggregator eventAggregator, IServiceLocator serviceLocator)
            :base(logger, regionManager, eventAggregator, serviceLocator)
        {
            this._logger.LogType = typeof(AlertHandlingViewModel);

            this.Model = "Hello, world!!";

            this._logger.Debug(GlobalConst.ObjectConstructed);
            this.Header = "BBBBB";
            var t = new DispatcherTimer(TimeSpan.FromSeconds(3), DispatcherPriority.Normal, Tick, this.Dispatcher);
        }

        public override bool KeepAlive
        {
            get
            {
                return true;
            }
        }

        public override bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return true;
        }

        void Tick(object sender, EventArgs e)
        {
            this.Header = "AAAAA" == this.Header.ToString() ? "BBBBB" : "AAAAA";
        }
    }
}
